package zeebe.head;

import io.zeebe.client.ZeebeClient;
import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.worker.JobClient;
import io.zeebe.client.api.worker.JobHandler;

public class HappyJobWorkerHandler implements JobHandler {
    ZeebeClient zeebeClient;

    public HappyJobWorkerHandler(ZeebeClient client) {
        this.zeebeClient = client;
    }

    @Override
    public void handle(JobClient jobClient, ActivatedJob activatedJob) throws Exception {
        System.out.println("开始执行HappyJobWorker");

        String method = activatedJob.getCustomHeaders().get("method");
        switch (method) {
            case "xiongjie":
                sayHello(method);
                jobClient.newCompleteCommand(activatedJob.getKey())
                        .send()
                        .join();
                break;
            case "hexingjie":
                sayGoodmorning(method);
                jobClient.newCompleteCommand(activatedJob.getKey())
                        .send()
                        .join();
                break;
            default:
                jobClient.newFailCommand(activatedJob.getKey());
                break;
        }
    }

    private void sayHello(String name) {
        System.out.println("hello: " + name);
    }

    private void sayGoodmorning(String name) {
        System.out.println("goodmorning: " + name);
    }
}
